package com.zzyl.controller;

import com.aliyun.iot20180120.models.QueryDeviceDetailRequest;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryThingModelPublishedRequest;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description DeviceController
 * @Author songyu
 * @Date 2024-05-23
 */
@RestController
@RequestMapping("/iot")
@Slf4j
public class DeviceController extends BaseController{

    @Autowired
    private DeviceService deviceService;

    /**
     * 处理从物联网平台同步产品列表
     * @return
     */
    @PostMapping("/syncProductList")
    public ResponseResult syncProductList(){
        log.info("处理从物联网平台同步产品列表...");

        deviceService.syncProductList();

        return success();
    }

    @GetMapping("/allProduct")
    @ApiOperation(value = "查询所有产品列表")
    public ResponseResult<List<ProductVo>> allProduct() {
        List<ProductVo> productVoList = deviceService.allProduct();
        return success(productVoList);
    }

    @PostMapping("/RegisterDevice")
    @ApiOperation(value = "注册设备")
    public ResponseResult<Void> registerDevice(@RequestBody DeviceDto deviceDto) {
        log.info("调用注册设备接口，参数：{}",deviceDto);

        //调用业务实现注册设备
        deviceService.registerDevice(deviceDto);
        //返回数据
        return success();
    }

    @GetMapping("/pageQueryDevice")
    @ApiOperation(value = "分页查询设备列表")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice(DevicePageQueryDto devicePageQueryDto) {
        //调用业务获取设备分页数据
        PageResponse<DeviceVo> pageResponse = deviceService.pageQueryDevice(devicePageQueryDto);
        //返回数据
        return success(pageResponse);
    }

    @PostMapping("/QueryDeviceDetail")
    @ApiOperation(value = "查询设备详细数据")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody QueryDeviceDetailRequest request) {

        //调用业务获取设备详情数据
        DeviceVo deviceVo = deviceService.queryDeviceDetail(request);
        //返回数据
        return success(deviceVo);
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation(value = "查询指定设备的物模型运行状态")
    public ResponseResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {
        return deviceService.queryDevicePropertyStatus(request);
    }

    @PostMapping("/QueryThingModelPublished")
    @ApiOperation(value = "查看指定产品的已发布物模型中的功能定义详情")
    public ResponseResult queryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request) {
        return deviceService.queryThingModelPublished(request);
    }


}
